import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core';
import * as screenFull from 'screenfull';

// 全屏插件
@Component({
  selector: 'app-header-fullscreen',
  template: `
      <i nz-icon [nzType]="status ? 'fullscreen-exit' : 'fullscreen'"></i>`,
  host: {
    '[class.d-block]': 'true',
  },
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HeaderFullScreenComponent {
  status = false;

  private get sf(): screenFull.Screenfull {
    return screenFull as screenFull.Screenfull;
  }

  @HostListener('window:resize')
  _resize() {
    this.status = this.sf.isFullscreen;
  }

  @HostListener('click')
  _click() {
    if (this.sf.isEnabled) {
      this.sf.toggle();
    }
  }
}
